/**
 *
 */
package com.ean.backpack.core.util;

import org.springframework.security.authentication.encoding.Md5PasswordEncoder;
import org.springframework.security.authentication.encoding.PasswordEncoder;

/**
 * @author valentin, cristian
 * 
 */
public class CoreUtils {
	private static PasswordEncoder passwordEncoder = new Md5PasswordEncoder();

	public static String getEncodedPassword(String password) {
		return passwordEncoder.encodePassword(password, null);
	}

	public static String convertDate(String date, UtilFormat startFormat,
			UtilFormat endFormat, String separator) {
		if (startFormat == UtilFormat.ddmmyyyy
				&& endFormat == UtilFormat.mmddyyyy) {
			String[] temp = date.trim().split(separator);
			return String.format("%s/%s/%s", temp[1], temp[0], temp[2]);
		} else if (startFormat == UtilFormat.ddmmyyyy
				&& endFormat == UtilFormat.yyyymmdd) {
			String[] temp = date.trim().split(separator);
			return String.format("%s/%s/%s", temp[2], temp[1], temp[0]);
		} else if (startFormat == UtilFormat.mmddyyyy
				&& endFormat == UtilFormat.ddmmyyyy) {
			String[] temp = date.trim().split(separator);
			return String.format("%s/%s/%s", temp[1], temp[0], temp[2]);
		} else if (startFormat == UtilFormat.mmddyyyy
				&& endFormat == UtilFormat.yyyymmdd) {
			String[] temp = date.trim().split(separator);
			return String.format("%s/%s/%s", temp[2], temp[1], temp[0]);
		}

		return date;
	}
	
	public enum UtilFormat {
		ddmmyyyy, mmddyyyy, yyyymmdd
	}

}
